package nckd.wnqjt.tmc.tda.plugin.form;

import kd.bos.algo.DataSet;
import kd.bos.entity.report.AbstractReportListDataPlugin;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zhujintao
 * @date 2024/11/05
 * @desc  低效账户单位分布
 */
public class InefficientAccountDetailListDataPlugin extends AbstractReportListDataPlugin {

    @Override
    public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
        //筛选出 筛选器传入的ids
        Map<String, Object> customParam = reportQueryParam.getCustomParam();
        List<String> list = (ArrayList<String>) customParam.get("id");
        List<Long> longList = list.stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
        //先获取到低效账户设置的参数
        //Map<String, Object> settingFilterMap = InefficientAccountQingDataProvider.dormantSettingFilter();
        String getDailySelectedFieds = "id,org.id orgid,org.number orgnumber,org.name orgname,accountbank.bankaccountnumber bankaccountnumber,bizdate";
        QFilter dailytimefilter = new QFilter("id", QCP.in, longList);
        //银行日记账
        DataSet bankJournalAllDataSet = QueryServiceHelper.queryDataSet("dormantAcct", "cas_bankjournal", getDailySelectedFieds, dailytimefilter.toArray(), (String) null);
        DataSet accountcountDataSet = bankJournalAllDataSet.groupBy(new String[]{"orgid", "bankaccountnumber"}).count("counttradecount").finish();
        return accountcountDataSet;
    }
}